#region license
# This file is part of Grawlix.
# 
# Grawlix is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
# 
# Grawlix is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public
# License along with Grawlix.  If not, see
# <http://www.gnu.org/licenses/>.
#endregion

"""An execution environment which injects into the current context."""

namespace Grawlix.Services
import Grawlix.Meta
import System
import System.Reflection

final class HostEnvironment(ExecutionEnvironment):
"""An execution environment which just wraps the current context."""
	
	def constructor():
	"""Initializes a HostEnvironment."""
		pass
	
	[Equality(OverloadOperators: true)]
	private def Equality(other as HostEnvironment):
	"""
	Equality testing.
	Param other: The environment to compare to.
	Returns: Always true.
	"""
		return true
	
	override def GetHashCode():
	"""
	Gets a value for the hash code.
	Returns: The same for all HostEnvironments.
	"""
		return 0
	
	override def LoadAssembly([required] fullName as string):
	"""
	Load and return a new instance.
	Param fullName: The full name of the assembly to load.
	Returns: The specified assembly.
	"""
		return Assembly.Load(fullName)
	
	override def CreateInstance(
		[required] instanceType as Type,
		[required] *arguments as (object)):
	"""
	Load and return a new instance.
	Param instanceType: The type of object to create.
	Param arguments: The arguments to pass to the constructor.
	Returns: The new instance.
	"""
		instance = instanceType(*arguments)
		# Sanity check; should throw under these conditions
		assert instance is not null
		# Warning: GetType() can cause injections in some cases
		assert instance.GetType() == instanceType
		return instance
	
	override def ToString():
	"""
	Get a string representation of this object.
	Returns: A string representation of this object.
	"""
		return "HostEnvironment ${AppDomain.CurrentDomain.FriendlyName}"
	
